<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<TITLE>合同类别管理</TITLE>
	<script language="javascript" src="../script/common.js"></script>
	<script language="javascript">
		//全局变量
		var qt = {};				//数据表格对象
		var org = Common.cOrg();
		//页面加载方法
		function load(){
			Eui.showNavigation();
			setPages(["listview","detview"]);
			if (org.orgLevel != Constants.ORG_LEVEL_HQ){
				$("selOrgLink").style.display = "none";
				setOrg(org);
			}
			createTable();		
		}
		/**查询部分**/

		//生成表格，创建QueryTable对象
		function createTable(){
			var columns = []	
			columns[0] = {type:"checkbox"}
			var buttons = []
			if (org.orgLevel != Constants.ORG_LEVEL_HQ){
				buttons.push({value:"新增合同",actions:onEdit})
				buttons.push({value:"删除合同",actions:onDelete})
				columns[2] = {
					render : function(v,r){
						return "<a href=# onclick=\"onEdit("+r[0]+")\">"+v+"</a>"
					}
				}
			}	
			qt = new QueryTable("contract_type","searchForm","datalist",columns,{
				buttons : buttons
			});
		}
		
		function onEdit(id){
			switchPage("detview");
			clearErrorView("contractTypeForm");
			contractTypeForm.reset();
			if (id){
				DWR.call("cardMgntService.getContractType",id,function(ct){
					Common.setValues("contractTypeForm",ct);
				},{blockScreen:true})
			}
		}
		function onDelete(){
			var ids = qt.getBoxValue();
			Eui.onDel("cardMgntService.deleteContractType",ids, "合同类别", null, function() {
				qt.showTable();
			});
		}
		function onSave(){
			if (!checkForm(contractTypeForm)) return;
			var contractType = Common.getValues(contractTypeForm)
			DWR.call("cardMgntService.saveContractType",contractType,function(){
				showInformation("合同类别保存成功！");
				switchPage('listview');
				qt.showTable();
			},{blockScreen:true})
		}
		//选择机构方法
		function searchSelOrg(){
			SystemMgnt.selOrg(setOrg,{funcType : Constants.SELORG_ALL});
		}
		
		function setOrg(sorg){
			searchForm.orgName.value = sorg.name;
			searchForm.organization.value = sorg.id;
		}
	</script>
</HEAD>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="listview" >	
		<!--查询条件form-->
		<form id="searchForm" name="searchForm">
			<input type="hidden" name="organization">
			<div class="searchForm">
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 >
					<tr>
				    	<td><label>合同名称</label> <input type="text"  name="name" maxlength="20"></td>
						<td>
							<label>创建机构</label> <input type="text" name="orgName" readonly class="readonly"><a id="selOrgLink" class="orga" href="#" onclick="searchSelOrg();">&nbsp;&nbsp;</a>
						</td>	
						<td><button type="button" onclick="qt.showTable()">查 询</button></td> 
					</tr> 
				</table>
			</div>
		</form>
		<!--查询结构列表-->
		<div id="datalist"></div>	
	</div>	
	<div id="detview" style="display:none;">
		<form id="contractTypeForm" name="contractTypeForm">
			<input type="hidden" name="id">
			<div class="form">
				<div class="formTitle">合同类型</div>	
				<table cellSpacing="0" cellPadding="4" width="100%" border="0">
					<tr>
						<td><label>名称</label> <input type="text" name="name" maxlength="20" onblur="checkV(this,'',true)"></span></td>
						<td><label>描述</label> <input type="text" name="description" maxlength="80"></td>
					</tr>	
				</table>
			</div>
			<p>
				<button type="button" onclick="onSave()">保 存</button>
				<button type="button" onclick="switchPage('listview')">返 回</button>
			</p>
		</form>
	</div>	
 </body>
</HTML>
